package com.moma.chatting.dao;

import java.util.ArrayList;
import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;

public class PersonDao extends SqlSessionDaoSupport implements IPersonDao {

	public Person selectById(Integer id) {   
		Person person = new Person();
        person = (Person)getSqlSession()
        		.selectOne("com.moma.chatting.dao.IPersonDao.selectPerson",id);
        return person;   
    }   
  
    @SuppressWarnings("unchecked")   
    public List<Person> selectAll() {   
        List<Person> persons = new ArrayList<Person>();
        persons = getSqlSession()
        		.selectList("com.moma.chatting.dao.IPersonDao.selectAll");
  
        return persons;   
    }   
  
    public void delete(Person person) {  
    	getSqlSession().delete("com.moma.chatting.dao.IPersonDao.deletePerson", person);
    }   
  
    public void insert(Person person) {
    	try{
    	getSqlSession().insert("com.moma.chatting.dao.IPersonDao.insertPerson", person);
    	}catch(Exception exception){
    		exception.printStackTrace();
    	}
    }   
  
    public void update(Person person) {  
    	getSqlSession().update("com.moma.chatting.dao.IPersonDao.updatePerson", person);   
    }   
  
    @SuppressWarnings("unchecked")   
    public List<Person> selectPersonsByName(String name) {   
        List<Person> persons = new ArrayList<Person>(); 
        persons = getSqlSession().selectList("com.moma.chatting.dao.IPersonDao.selectPersonsByName", "%"  
                            + name + "%");  
        return persons;   
    }   

}
